package swa2012.telco.client;

import java.util.List;

import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;

import swa2012.telco.broker.BrokerSendMessageStatus;
import swa2012.telco.broker.Client;
import swa2012.telco.broker.Message;
import swa2012.telco.provider.IProvider;
import swa2012.telco.provider.ProviderImpl;

public class ClientConnector {
	IProvider provider = null;
	public ClientConnector() {
		JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
		factory.setServiceClass(IProvider.class);
		factory.setAddress("http://localhost:8080/telco/Provider");
		factory.getInInterceptors().add(new LoggingInInterceptor());
		factory.getOutInterceptors().add(new LoggingOutInterceptor());
		//provider = (IProvider) factory.create();
		provider = ProviderImpl.getInstance();
		provider.connectBroker();
	}
	
	public void registerClient(Client client) {
		provider.registerClient(client);
	}
	
	public void unregisterClient(Client client) {
		provider.unregisterClient(client);	
	}
	
	public BrokerSendMessageStatus sendMessage(Message message) {
		return provider.sendMessage(message);
	}
	
	public List<Client> getClientList() {
		return provider.getClientList();
	}
}
